package com.bingfor.easycablelink.account.viewmodel;

import android.databinding.ObservableInt;

import com.bingfor.easycablelink.R;
import com.bingfor.easycablelink.account.ForgotPasswordActivity;
import com.bingfor.easycablelink.account.MainActivity;
import com.bingfor.easycablelink.account.RegisterActivity;
import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.home.TestActivity;
import com.bingfor.easycablelink.widgets.ViewModel;

/**
 * Created by LY on 2017/5/17.
 */

public class LoginViewModel implements ViewModel {

    private BaseActivity mContext;
    public String phone = "";
    public String password = "";
    public ObservableInt style = new ObservableInt(0);//0 账号登录  1,密码登录


    public LoginViewModel(BaseActivity mContent) {
        this.mContext = mContent;
    }

    /**
     * 登录
     */
    public void login() {

        mContext.moveToNextPage(MainActivity.class);
        mContext.overridePendingTransition(0,R.anim.slide_bottom_in);
//        if (StringUtils.isEmpty(phone)) {
//            mContext.showSnakeBar("请输入手机号");
//            return;
//        }
//        if (!StringUtils.isPhone(phone)) {
//            mContext.showSnakeBar("请输入正确的手机号");
//            return;
//        }
//        if (StringUtils.isEmpty(password)) {
//            mContext.showSnakeBar("请输入密码");
//            return;
//        }
//
//        ApiRetrofit.getInstance()
//                .login(phone, password)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<HttpResult>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        mContext.showSnakeBar("登录失败，请检查账号密码是否正确.");
//
//                    }
//
//                    @Override
//                    public void onNext(HttpResult httpResult) {
//
//                        if (httpResult.getStatus() == 1) {
//                            ToastUtil.showToast("登录成功");
//
//                        } else {
//                            mContext.showSnakeBar(httpResult.getMsg());
//                        }
//                    }
//                });
    }

    public ObservableInt getStyle() {
        return style;
    }

    public void setStyle() {
        style.set(style.get()==0?1:0);
        style.notifyChange();
    }

    public void toForgotPassword(){
        mContext.moveToNextPage(ForgotPasswordActivity.class);
    }

    public void toRegister(){
        mContext.moveToNextPage(RegisterActivity.class);
    }
}
